package com.douqu.game.core.container;


import com.douqu.game.core.config.StableDataConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.e.E_NoticeType;
import com.douqu.game.core.factory.FunctionFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.CoreUtils;
import com.douqu.game.core.util.LogUtils;

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* 主角容器   容在区域房间战斗
* @author bean
*
*/
public class PlayerContainer implements Serializable
{
	protected static final long serialVersionUID = 1L;

	protected List<PlayerController> playerList = new CopyOnWriteArrayList();


	public List getPlayerList()
	{
		return playerList;
	}

	public PlayerController getPlayerByIndex(int index)
	{
		return playerList.get(index);
	}


	public int getPlayerCount()
	{
		return playerList.size();
	}


	/**
	 * 转发容器内所有的消息
	 * @param
	 */
	public void dispatchMsg(int code, byte[] data)
	{
		for(PlayerController playerController : playerList)
		{
			playerController.sendMsg(code, data);
		}
	}

	/**
	 * 转发容器内所有的消息
	 * @param
	 */
	public void dispatchGet(String data)
	{
		for(PlayerController playerController : playerList)
		{
			playerController.sendGet(data);
		}
	}





	/**
	 * 转发容器内所有的消息
	 * @param
	 */
	public void dispatchWarn(String key, Object... params)
	{
		for(PlayerController playerController : playerList)
		{
			playerController.sendWarn(key, params);
		}
	}

	/**
	 * 转发容器内所有的消息
	 * @param
	 */
	public void dispatchGM(String content,E_NoticeType... noticeType)
	{
		for(PlayerController playerController : playerList)
		{
			if (noticeType != null && noticeType.length > 0){
				if (noticeType[0].equals(E_NoticeType.NOTICE_TYPE_BOSS)){
					//如果是boss推送 判断用户是否开启boss战
					//如果等级不够不推送
					if (!CoreUtils.isFunctionUnLock(FunctionFactory.WORLD_BOSS, playerController.getPlayer())){
						continue;
					}
				}
			}
			playerController.sendGM(content);
		}
	}



}
